package threadUtils.demo05;

import java.util.Date;
import java.util.concurrent.Phaser;
import java.util.concurrent.TimeUnit;

public class PhaserExample01 {

    public static void main(String[] args) throws InterruptedException {

        final Phaser phaser = new Phaser();

        for (int i = 0; i < 10; i++) {
            new Thread(() -> {
                int register = phaser.register();
                System.out.println(register);
                try {
                    TimeUnit.SECONDS.sleep(10);
                    phaser.arrive();
                    System.out.println(new Date() + "：" + Thread.currentThread().getName() + " complete");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }).start();
        }
        TimeUnit.SECONDS.sleep(5);
        phaser.arriveAndAwaitAdvance();
        System.out.println(new Date() + ": all completed");

    }

}
